const { get_fst_file, get_full_path } = require("../utils/file_tool");
const { BaseCommand } = require("./base");
const Jimp = require("jimp");

class ImageCropCommand extends BaseCommand {
    async execute() {
        const data = this.selfData;
        const src = get_fst_file(data.src);
        const image = await Jimp.read(src);
        const { x, y, w, h } = data.region;
        const croped = image.crop(x, y, w, h);
        const dst = get_full_path(data.dst);
        await croped.writeAsync(dst);
    }
}

module.exports = {
    ImageCropCommand,
};
